#include<bits/stdc++.h>
#define int long long
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define rep(i  ,b) for(int i=1,i##end=b;i<=i##end;i++)
using namespace std;
const int N=1e6+9;
int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return f?-x:x;
}
int n;
struct node{
	int a,b;
	bool operator<(const node&X)const{
		return b<X.b;
	}
}A[N];int ans[N];
signed main(){
	freopen("boast.in","r",stdin);
	freopen("boast.out","w",stdout);
	n=read();
	rep(i,n)A[i].a=read(),A[i].b=read();
	sort(A+1,A+1+n);
	int mn=1e18;
	rep(i,n){
		ans[i]+=mn;
		mn=min(mn,A[i].a);
	}mn=1e18;
	Rof(i,n,1){
		ans[i]+=mn;
		mn=min(mn,A[i].a+A[i].b);
	}
	int res=1e18;
	rep(i,n)res=min(res,ans[i]+A[i].a+A[i].b);
	cout<<res<<endl;
	return 0;
}

